#import "FlutterKxCryptoPlugin.h"
#import "KXCrypto3DES.h"
@implementation FlutterKxCryptoPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
  FlutterMethodChannel* channel = [FlutterMethodChannel
      methodChannelWithName:@"flutter_kx_crypto"
            binaryMessenger:[registrar messenger]];
  FlutterKxCryptoPlugin* instance = [[FlutterKxCryptoPlugin alloc] init];
  [registrar addMethodCallDelegate:instance channel:channel];
}

- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
  if ([@"getPlatformVersion" isEqualToString:call.method]) {
    result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
  } else if([@"encrypt3DES" isEqualToString:call.method]) {
    NSDictionary* argsMap=call.arguments;
    NSString * data=argsMap[@"data"];
    NSString * key=argsMap[@"key"];
    NSString *encryptString = [self encrypt3DES:data key:key];
    if (encryptString) {
        result(encryptString);
    } else
    {
        result([FlutterError errorWithCode:@"UNAVAILABLE"
        message:@"encrypt3DES unavailable"
        details:nil]);
    }
  }else if([@"decrypt3DES" isEqualToString:call.method]){
      NSDictionary* argsMap=call.arguments;
      NSString * data=argsMap[@"data"];
      NSString * key=argsMap[@"key"];
      NSString *decryptString = [self decrypt3DES:data key:key];
      if (decryptString) {
          result(decryptString);
      } else
      {
          result([FlutterError errorWithCode:@"UNAVAILABLE"
          message:@"decrypt3DES unavailable"
          details:nil]);
      }
  } else {
    result(FlutterMethodNotImplemented);
  }
}
- (NSString *)encrypt3DES:(NSString *)data key:(NSString *)key {

    return [KXCrypto3DES encrypt3DES:data key:key];
}

- (NSString *)decrypt3DES:(NSString *)data key:(NSString *)key {

    return [KXCrypto3DES decrypt3DES:data key:key];
}
@end
